/*
 * Copyright (c) 2015. For Intelligent Group.
 */

package com.intelligent.ispc.export.grr;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.intelligent.ispc.common.utils.StringUtils;
import com.intelligent.ispc.core.dto.*;
import com.intelligent.ispc.core.entity.DUTAttribute;
import com.intelligent.ispc.core.entity.TestData;
import com.intelligent.ispc.core.entity.TestItem;
import com.intelligent.ispc.foundation.poi.*;
import com.intelligent.ispc.utils.Constant;
import com.intelligent.ispc.utils.ExportLabelConstant;
import com.intelligent.ispc.utils.SummaryRuleStyle;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by cherry on 2016/6/2.
 */
public class GrrExportCellFactory implements ExCellFactory {


    private XSSFWorkbook workbook = new XSSFWorkbook();
    private List<ExSheet> sheets = new ArrayList<>();

    Map<String, XSSFCellStyle> mapRuleStyle = Maps.newHashMap();
    Map<String, XSSFCellStyle> mapCellStyle = Maps.newHashMap();

    private Integer[] headIndex = new Integer[]{0, 0};
    private Integer[] dataIndex = new Integer[]{5, 1};
    private Integer currentRow = 0;
    private int digGrrNum = 4;
    private Double[] grrRules = new Double[3];

    public void buildGRRBySlot(Map<String, Object> searchParams, List<GRRSummaryDto> grrSummaryDtoList, List<GRRExportResultDto> grrExportResultDtoList, List<GRRTestDataDto> grrTestDataDtoList, List<PSAttributeDto> psAttributeDtoList) {

        mapCellStyle = CellStyleUtil.getStyle(this.getCurrentWorkbook());
        ExSheet exSheet = new ExSheet();
        String model = "";

        if (searchParams.containsKey(Constant.GRR_MODEL_VALUE)) {
            model = (String) searchParams.get(Constant.GRR_MODEL_VALUE);
        }

        List<ExCell> cellList = Lists.newArrayList();
        List<ExCell> summaryHead = buildSummaryHead(searchParams);
        List<ExCell> summaryContent = buildSummaryContent(grrSummaryDtoList);
        cellList.addAll(summaryHead);
        cellList.addAll(summaryContent);
        exSheet.setExCells(cellList);
        sheets.add(exSheet);
        exSheet.setName(Constant.GRR_EXPORT_SUMMARY);

        if (grrExportResultDtoList != null) {

            String sigma = "";
            if (searchParams.containsKey(Constant.GRR_SIGMA_VALUE)) {
                sigma = searchParams.get(Constant.GRR_SIGMA_VALUE) + "";
            }

            int j = 0;
            for (int i = 0; i < grrSummaryDtoList.size(); i++) {

                if (j >= grrExportResultDtoList.size()) {
                    break;
                }

                String summaryItemName = grrSummaryDtoList.get(i).getItemName();
                String subItemName = grrExportResultDtoList.get(j).getGrrExportParamDto().getTestItemName();
                if (summaryItemName.equals(subItemName)) {
                    ExSheet exSheetItem = new ExSheet();
                    exSheetItem.setName(grrExportResultDtoList.get(j).getGrrExportParamDto().getTestItemName());
                    exSheetItem.setIndex(i + 1);
                    List<ExCell> itemsCellList = buildGRRTestItem(sigma, model, grrExportResultDtoList.get(j));
                    exSheetItem.setExCells(itemsCellList);
                    sheets.add(exSheetItem);
                    j++;
                }
            }
        }

        if (grrTestDataDtoList != null) {
            ExSheet exSheetItem = new ExSheet();
            exSheetItem.setName(grrTestDataDtoList.get(0).getGrrName());
            List<ExCell> exCellDataList = Lists.newArrayList();
            Map<String, Object> testData = grrTestDataDtoList.get(0).getTestData();
            List<DUTAttribute> dutAttributes = grrTestDataDtoList.get(0).getDutAttributes();
            List<TestItem> testItems = grrTestDataDtoList.get(0).getTestItems();
            exCellDataList.addAll(buildGrrDataTitle(testData, dutAttributes, testItems, psAttributeDtoList));
            for (int i = 0; i < grrTestDataDtoList.size(); i++) {
                Map<String, Object> grrTestData = grrTestDataDtoList.get(i).getTestData();
                List<DUTAttribute> grrDutAttributes = grrTestDataDtoList.get(i).getDutAttributes();
                List<TestItem> grrTestItems = grrTestDataDtoList.get(i).getTestItems();
                exCellDataList.addAll(buildGrrData(grrTestData, grrDutAttributes, grrTestItems));
            }
            exSheetItem.setExCells(exCellDataList);
            sheets.add(exSheetItem);
        }
    }

    //    fill title and params (Excellent, Adequate……index)
    private List<ExCell> buildSummaryHead(Map<String, Object> searchParams) {
        List<ExCell> exCellList = Lists.newArrayList();
        String[] titleLabels_one = ExportLabelConstant.EXPORT_SUMMARY_LABELS_ONE;
        String[] titleLabels_two = ExportLabelConstant.EXPORT_SUMMARY_LABELS_TWO;
        String[] summaryRules = ExportLabelConstant.EXPORT_SUMMARY_RULES;

        if (searchParams.containsKey("rule")) {
            String rule = ((String) searchParams.get("rule"));
            if (rule.length() > 1) {
                rule = rule.substring(1, rule.length() - 1);
                String rules[] = rule.split(",");
                for (int i = 0; i < rules.length; i++) {
                    if (i == 3) break;
                    grrRules[i] = new Double(rules[i]);
                }

                int n = 0;
                int startCol = 9;
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol}, "<" + rules[0] + "%", ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_text.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol + 1}, summaryRules[0], ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_Excellent.toString())));

                n++;
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol}, rules[0] + "% ~ " + rules[1] + "%", ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_text.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol + 1}, summaryRules[1], ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_Adequate.toString())));

                n++;
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol}, rules[1] + "% ~ " + rules[2] + "%", ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_text.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol + 1}, summaryRules[2], ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_Marginal.toString())));

                n++;
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol}, ">" + rules[2] + "%", ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_text.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol + 1}, summaryRules[3], ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_Bad.toString())));
            }
        }

        for (int i = 0; i < titleLabels_one.length; i++) {
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0], headIndex[1] + i}, titleLabels_one[i], ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_title.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + 1, headIndex[1] + i}, titleLabels_two[i], ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_title.toString())));
        }
        return exCellList;
    }

    private List<ExCell> buildSummaryContent(List<GRRSummaryDto> grrSummaryDtoList) {
        List<ExCell> exCellList = Lists.newArrayList();

        mapRuleStyle = SummaryRuleStyle.getBackStyle(this.getCurrentWorkbook());
        for (int i = 0; i < grrSummaryDtoList.size(); i++) {
            int n = 0;
            String name = grrSummaryDtoList.get(i).getItemName();
            String lsl = grrSummaryDtoList.get(i).getLsl();
            String usl = grrSummaryDtoList.get(i).getUsl();
            String tolerance = grrSummaryDtoList.get(i).getTolerance();
            String partVariation = grrSummaryDtoList.get(i).getPartVariation();
            String totalProcessVariation = grrSummaryDtoList.get(i).getTotalProcessVariation();
            String grr = grrSummaryDtoList.get(i).getGrr();
            String result = grrSummaryDtoList.get(i).getResult();
            if (("EXCELLENT").equals(result)) {
                result = ExportLabelConstant.EXPORT_SUMMARY_EXCELLENT;
            }

            if (("GOOD").equals(result)) {
                result = ExportLabelConstant.EXPORT_SUMMARY_ADEQUTE;
            }

            if (("ACCEPTABLE").equals(result)) {
                result = ExportLabelConstant.EXPORT_SUMMARY_MARGIMAL;
            }

            if (("RECTIFICATION").equals(result)) {
                result = ExportLabelConstant.EXPORT_SUMMARY_BAD;
            }
            String arr[] = {name, lsl, usl, tolerance, partVariation, totalProcessVariation, grr, result};
            for (int j = 0; j < arr.length; j++) {
                if (StringUtils.isBlankWithSpecialNumber(arr[j]) || ("Infinity").equals(arr[j])) {
                    arr[j] = "-";
                }
            }
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, (i + 1) + "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[0], ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[1].equals("-") ? "-" : formatDouble(Double.valueOf(arr[1]), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[2].equals("-") ? "-" : formatDouble(Double.valueOf(arr[2]), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[3].equals("-") ? "-" : formatDouble(Double.valueOf(arr[3]), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[4].equals("-") ? "-" : formatDouble(Double.valueOf(arr[4]), 2) + "%", ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[5].equals("-") ? "-" : formatDouble(Double.valueOf(arr[5]), 2) + "%", ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[6].equals("-") ? "-" : formatDouble(Double.valueOf(arr[6]), 2) + "%", ExCellType.TEXT, mapRuleStyle.get(result)));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[7], ExCellType.TEXT, mapRuleStyle.get(result)));
        }

        return exCellList;
    }

    private List<ExCell> buildGRRTestItem(String sigma, String type, GRRExportResultDto grrExportResultDto) {
        List<ExCell> exCellList = Lists.newArrayList();
        currentRow = 0;
        List<ExCell> exCellParamList = buildTestItemGRRParam(grrExportResultDto.getGrrExportParamDto(), type);
        double trialCount = Double.valueOf(grrExportResultDto.getGrrExportParamDto().getTrialCount());
        List<ExCell> exCellGRRDataList = buildTestItemGRRData((int) trialCount, type, grrExportResultDto.getGrrDataDtoList(), grrExportResultDto.getGrrStatisticDataDtoList());
        List<ExCell> exCellGRRAnovaList = buildTestItemGRRAnova(grrExportResultDto.getGrrAnovaDtoList());
        List<ExCell> exCellGRRSourceList = buildTestItemGRRSource(grrExportResultDto.getGrrSourceDtoList(), sigma);
        List<ExCell> exCellGRRImagesList = buildTestItemGRRImages(grrExportResultDto.getImgPaths());
        exCellList.addAll(exCellParamList);
        exCellList.addAll(exCellGRRDataList);
        exCellList.addAll(exCellGRRAnovaList);
        exCellList.addAll(exCellGRRSourceList);
        exCellList.addAll(exCellGRRImagesList);
        return exCellList;
    }

    private List<ExCell> buildTestItemGRRParam(GRRExportParamDto grrExportParamDto, String type) {
        List<ExCell> exCellList = Lists.newArrayList();

        exCellList.add(ExUtil.fillToCell(new Integer[]{1, 1}, "Test Item", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{1, 2}, grrExportParamDto.getTestItemName(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_2.toString())));

        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 1}, "USL", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 2}, grrExportParamDto.getUsl(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_2.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 3}, "LSL", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 4}, grrExportParamDto.getLsl(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_2.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 5}, "Tolerance", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 6}, grrExportParamDto.getTolerance(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_3.toString())));

        if (("NORMAL").equals(type)) {
            type = "Appraisers";
        }
        exCellList.add(ExUtil.fillToCell(new Integer[]{1, 8}, "Number of " + type + " = ", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_m_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{2, 8}, "Number of Parts = ", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_m_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 8}, "Number of Trials = ", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_m_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{1, 9}, grrExportParamDto.getOperatorCount(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_m_2.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{2, 9}, grrExportParamDto.getSnCount(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_m_2.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 9}, grrExportParamDto.getTrialCount(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_m_2.toString())));

        exCellList.add(ExUtil.fillToCell(new Integer[]{2, 11}, "Date: ", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 11}, "Performed By: ", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{2, 12}, grrExportParamDto.getExportTime(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_2.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 12}, grrExportParamDto.getPerformedBy(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_2.toString())));
        return exCellList;
    }

    private List<ExCell> buildTestItemGRRData(int trialCount, String type, List<GRRDataDto> grrDataDtoList, List<GRRStatisticDataDto> grrStatisticDataDtoList) {
        List<ExCell> exCellList = Lists.newArrayList();

        if (grrDataDtoList.size() > 0) {
            int count = grrDataDtoList.size() / trialCount;
            int cursor = 0;
            int n = 0;

            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, type, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_title.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "Trial", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_title.toString())));
            for (int k = 0; k < grrDataDtoList.get(0).getColValueDtoList().size(); k++) {
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, grrDataDtoList.get(0).getColValueDtoList().get(k).getKey(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_title.toString())));
            }
            currentRow++;

            for (int i = 0; i < count; i++) {
                int m = 0;
                for (int j = cursor; j < cursor + trialCount; j++) {
                    GRRDataDto grrDataDto = grrDataDtoList.get(j);
                    m = 0;
                    exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++}, grrDataDto.getOperator(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_operator.toString())));
                    exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++}, grrDataDto.getTrial(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_trial.toString())));
                    for (int k = 0; k < grrDataDto.getColValueDtoList().size(); k++) {
                        String value = String.valueOf(grrDataDto.getColValueDtoList().get(k).getValue());
                        if (StringUtils.isBlankWithSpecialNumber(value) || ("Infinity").equals(value)) {
                            value = "-";
                        }
                        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++}, ("-").equals(value) ? value : formatDouble(Double.valueOf(value), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_data.toString())));
                    }
                    currentRow++;
                }

                GRRStatisticDataDto grrStatisticDataDto = grrStatisticDataDtoList.get(i);
                m = 0;
                String rangeValue = grrStatisticDataDto.getRang();
                if (StringUtils.isBlankWithSpecialNumber(rangeValue) || ("Infinity").equals(rangeValue)) {
                    rangeValue = "-";
                }
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++}, ("-").equals(rangeValue) ? rangeValue : formatDouble(Double.valueOf(rangeValue), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_rangeData.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++}, "Range", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_rangeName.toString())));
                for (int i1 = 0; i1 < grrStatisticDataDto.getRangList().size(); i1++) {
                    String rValue = String.valueOf(grrStatisticDataDto.getRangList().get(i1).getValue());
                    if (StringUtils.isBlankWithSpecialNumber(rValue) || ("Infinity").equals(rValue)) {
                        rValue = "-";
                    }
                    exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++}, ("-").equals(rValue) ? rValue : formatDouble(Double.valueOf(rValue), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_rangeData.toString())));
                }
                currentRow++;
                String meanValue = grrStatisticDataDto.getMean();
                if (StringUtils.isBlankWithSpecialNumber(meanValue) || ("Infinity").equals(meanValue)) {
                    meanValue = "-";
                }
                m = 0;
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++}, ("-").equals(meanValue) ? meanValue : formatDouble(Double.valueOf(meanValue), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_avgData.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++}, "AVG", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_avgName.toString())));
                for (int i1 = 0; i1 < grrStatisticDataDto.getMeanList().size(); i1++) {
                    String mValue = String.valueOf(grrStatisticDataDto.getMeanList().get(i1).getValue());
                    if (StringUtils.isBlankWithSpecialNumber(mValue) || ("Infinity").equals(mValue)) {
                        mValue = "-";
                    }
                    exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++}, ("-").equals(mValue) ? mValue : formatDouble(Double.valueOf(mValue), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_avgData.toString())));
                }
                currentRow++;
                cursor += trialCount;
            }

            int size = grrStatisticDataDtoList.size();
            GRRStatisticDataDto grrStatisticDataTotalDto = grrStatisticDataDtoList.get(size - 1);
            List<BaseDto> totalMeanList = grrStatisticDataTotalDto.getTotalMeanList();
            List<BaseDto> totalRangList = grrStatisticDataTotalDto.getTotalRangList();
            n = 0;

            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n}, "Part Range", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_totalName.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow + 1, dataIndex[1] + n}, "Part AVGS", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_totalName.toString())));
            n++;

            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_totalName.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow + 1, dataIndex[1] + n}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_totalName.toString())));
            n++;

            for (int i = 0; i < totalMeanList.size(); i++) {
                String totalRange = String.valueOf(totalRangList.get(i).getValue());
                if (StringUtils.isBlankWithSpecialNumber(totalRange) || ("Infinity").equals(totalRange)) {
                    totalRange = "-";
                }
                String totalMean = String.valueOf(totalMeanList.get(i).getValue());
                if (StringUtils.isBlankWithSpecialNumber(totalMean) || ("Infinity").equals(totalMean)) {
                    totalMean = "-";
                }
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n}, ("-").equals(totalRange) ? totalRange : formatDouble(Double.valueOf(totalRange), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_rangeData.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow + 1, dataIndex[1] + n}, ("-").equals(totalMean) ? totalMean : formatDouble(Double.valueOf(totalMean), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_rangeData.toString())));
                n++;
            }

            currentRow += 3;
        }
        return exCellList;
    }

    private List<ExCell> buildTestItemGRRAnova(List<GRRAnovaDto> grrAnovaDtoList) {
        List<ExCell> exCellList = Lists.newArrayList();
        String[] anovaTitle = ExportLabelConstant.EXPORT_ANOVA_LABELS;
        int n = 0;
        for (int i = 0; i < anovaTitle.length; i++) {

            XSSFCellStyle style = mapCellStyle.get(CellStyleType.testItems_tbAnova_title_horizonal_m.toString());
            if (i == 0) {
                style = mapCellStyle.get(CellStyleType.testItems_tbAnova_title_horizonal_l.toString());
            }

            if (i == anovaTitle.length - 1) {
                style = mapCellStyle.get(CellStyleType.testItems_tbAnova_title_horizonal_r.toString());
            }
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, anovaTitle[i], ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, style));
        }
        currentRow++;

        for (int i = 0; i < grrAnovaDtoList.size(); i++) {
            n = 0;
            String keyValue = grrAnovaDtoList.get(i).getKeyValue();
            String dfValue = grrAnovaDtoList.get(i).getDfValue();
            String ssValue = grrAnovaDtoList.get(i).getSsValue();
            String msValue = grrAnovaDtoList.get(i).getMsValue();
            String fValue = grrAnovaDtoList.get(i).getfValue();
            String probFValue = grrAnovaDtoList.get(i).getProbFValue();
            String arr[] = {keyValue, dfValue, ssValue, msValue, fValue, probFValue};
            for (int j = 0; j < arr.length; j++) {
                if (StringUtils.isBlankWithSpecialNumber(arr[j]) || ("Infinity").equals(arr[j])) {
                    arr[j] = "-";
                }
            }
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, arr[0], ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_title_vertical.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_title_vertical.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, arr[1].equals("-") ? "-" : formatDouble(Double.valueOf(arr[1]), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, arr[2].equals("-") ? "-" : formatDouble(Double.valueOf(arr[2]), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, arr[3].equals("-") ? "-" : formatDouble(Double.valueOf(arr[3]), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, arr[4].equals("-") ? "-" : formatDouble(Double.valueOf(arr[4]), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, arr[5].equals("-") ? "-" : formatDouble(Double.valueOf(arr[5]), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            currentRow++;
        }

        currentRow++;
        return exCellList;
    }

    private List<ExCell> buildTestItemGRRSource(List<GRRSourceDto> grrSourceDtoList, String sigama) {
        List<ExCell> exCellList = Lists.newArrayList();
        String[] sourceTitle = ExportLabelConstant.EXPORT_SOURCE_LABELS;
        String categories = ExportLabelConstant.EXPORT_GRR_ITEM_CATEGORIES;
        int n = 0;

        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "Process of Distribution Width in Sigma's =  ", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_params_name.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_params_name.toString())));
        for (int i = 0; i < sourceTitle.length - 2; i++) {
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_params_name.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_params_name.toString())));
        }
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, sigama, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_params_value.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_params_value.toString())));
        currentRow++;
        n = 0;

        for (int i = 0; i < sourceTitle.length; i++) {
            String title = sourceTitle[i];
            if (i == 3) {
                title = sigama + " " + title;
            }

            XSSFCellStyle styleTitle = mapCellStyle.get(CellStyleType.testItems_tbSource_title_horizonal_m.toString());
            if (i == 0) {
                styleTitle = mapCellStyle.get(CellStyleType.testItems_tbSource_title_horizonal_l.toString());
            }

            if (i == sourceTitle.length - 1) {
                styleTitle = mapCellStyle.get(CellStyleType.testItems_tbSource_title_horizonal_r.toString());
            }

            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, title, ExCellType.TEXT, styleTitle));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, styleTitle));
        }

        currentRow++;

        for (int i = 0; i < grrSourceDtoList.size(); i++) {
            n = 0;
            String keyValue = grrSourceDtoList.get(i).getKeyValue();
            String variation = grrSourceDtoList.get(i).getVariation();
            String sigma = grrSourceDtoList.get(i).getSigma();
            String xSigma = grrSourceDtoList.get(i).getxSigma();
            String contribution = grrSourceDtoList.get(i).getContribution();
            String totalVariation = grrSourceDtoList.get(i).getTotalVariation();
            String tolerance = grrSourceDtoList.get(i).getTolerance();
            String arr[] = {keyValue, variation, sigma, xSigma, contribution, totalVariation, tolerance};
            for (int j = 0; j < arr.length; j++) {
                if (StringUtils.isBlankWithSpecialNumber(arr[j]) || ("Infinity").equals(arr[j])) {
                    arr[j] = "-";
                }
            }
            XSSFCellStyle style = mapCellStyle.get(CellStyleType.testItems_tbSource_content.toString());
            XSSFCellStyle grrStyle = mapRuleStyle.get(ExportLabelConstant.EXPORT_SUMMARY_EXCELLENT);
            if (("Appraisers").equals(keyValue) || ("Appraisers*Parts").equals(keyValue)) {
                style = mapCellStyle.get(CellStyleType.testItems_tbSource_content.toString());
            }

            if (("Gage R&R").equals(arr[0]) && grrRules.length >= 3 && !("-").equals(arr[6])) {
                if (Double.valueOf(arr[6]) <= grrRules[0]) {
                    grrStyle = mapRuleStyle.get(ExportLabelConstant.EXPORT_SUMMARY_EXCELLENT);
                }

                if (Double.valueOf(arr[6]) > grrRules[0] && Double.valueOf(arr[6]) <= grrRules[1]) {
                    grrStyle = mapRuleStyle.get(ExportLabelConstant.EXPORT_SUMMARY_ADEQUTE);
                }

                if (Double.valueOf(arr[6]) > grrRules[1] && Double.valueOf(arr[6]) <= grrRules[2]) {
                    grrStyle = mapRuleStyle.get(ExportLabelConstant.EXPORT_SUMMARY_MARGIMAL);
                }

                if (Double.valueOf(arr[6]) > grrRules[2]) {
                    grrStyle = mapRuleStyle.get(ExportLabelConstant.EXPORT_SUMMARY_BAD);
                }
            }

            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, arr[0], ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_title_vertical.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, arr[1].equals("-") ? "-" : formatDouble(Double.valueOf(arr[1]), digGrrNum), ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, arr[2].equals("-") ? "-" : formatDouble(Double.valueOf(arr[2]), digGrrNum), ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, arr[3].equals("-") ? "-" : formatDouble(Double.valueOf(arr[3]), digGrrNum), ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, arr[4].equals("-") ? "-" : formatDouble(Double.valueOf(arr[4]), 2) + "%", ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, arr[5].equals("-") ? "-" : formatDouble(Double.valueOf(arr[5]), 2) + "%", ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, arr[6].equals("-") ? "-" : formatDouble(Double.valueOf(arr[6]), 2) + "%", ExCellType.TEXT, ("Gage R&R").equals(arr[0]) ? grrStyle : style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, ("Gage R&R").equals(arr[0]) ? grrStyle : style));
            currentRow++;
        }
        currentRow++;
        n = 0;

        String distincCategories = "-";
        if (!grrSourceDtoList.isEmpty()) {
            int size = grrSourceDtoList.size();
            distincCategories = grrSourceDtoList.get(size - 1).getDistincCategories();
        }
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, categories, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, distincCategories, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_categoriesValue.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_categoriesValue.toString())));
        currentRow++;
        return exCellList;
    }

    private List<ExCell> buildTestItemGRRImages(List<String> imgPaths) {
        List<ExCell> exCellList = Lists.newArrayList();
        int n = 9;
        int m = 29;
        currentRow++;
        exCellList.add(ExUtil.fillToCell(new Integer[]{0, 0, 1023, 255, dataIndex[1], dataIndex[0] + currentRow, dataIndex[1] + n, dataIndex[0] + currentRow + m}, imgPaths.get(0), ExCellType.IMAGE));
        currentRow += m + 2;
        exCellList.add(ExUtil.fillToCell(new Integer[]{0, 0, 1023, 255, dataIndex[1], dataIndex[0] + currentRow, dataIndex[1] + n, dataIndex[0] + currentRow + m}, imgPaths.get(1), ExCellType.IMAGE));
        currentRow += m + 2;
        exCellList.add(ExUtil.fillToCell(new Integer[]{0, 0, 1023, 255, dataIndex[1], dataIndex[0] + currentRow, dataIndex[1] + n, dataIndex[0] + currentRow + m}, imgPaths.get(2), ExCellType.IMAGE));
        currentRow += m + 2;
        exCellList.add(ExUtil.fillToCell(new Integer[]{0, 0, 1023, 255, dataIndex[1], dataIndex[0] + currentRow, dataIndex[1] + n, dataIndex[0] + currentRow + m}, imgPaths.get(3), ExCellType.IMAGE));
        currentRow += m + 2;
        exCellList.add(ExUtil.fillToCell(new Integer[]{0, 0, 1023, 255, dataIndex[1], dataIndex[0] + currentRow, dataIndex[1] + n, dataIndex[0] + currentRow + m}, imgPaths.get(4), ExCellType.IMAGE));
        currentRow += m + 2;
        exCellList.add(ExUtil.fillToCell(new Integer[]{0, 0, 1023, 255, dataIndex[1], dataIndex[0] + currentRow, dataIndex[1] + n, dataIndex[0] + currentRow + m}, imgPaths.get(5), ExCellType.IMAGE));
        currentRow = 0;
        return exCellList;
    }

    private List<ExCell> buildGrrData(Map<String, Object> testData, List<DUTAttribute> dutAttributes, List<TestItem> testItems) {
        List<ExCell> exCellList = Lists.newArrayList();
        int n = 0;
        String title = "";
        for (String key : testData.keySet()) {
            if (TestData.PSA_START_TIME.equals(key) || TestData.PSA_STOP_TIME.equals(key)) {
                Date date = (Date) testData.get(key);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                title = sdf.format(date);
            } else {
                if ((TestData.PSA_IS_PASS).equals(key)) {
                    if (("true").equals(testData.get(key).toString())) {
                        title = "PASS";
                    } else if (("false").equals(testData.get(key).toString())) {
                        title = "FAIL";
                    } else {
                        title = testData.get(key).toString();
                    }
                } else {
                    title = testData.get(key).toString();
                }
            }
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow, headIndex[1] + n++}, title, ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
        }
        for (int i = 0; i < dutAttributes.size(); i++) {
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow, headIndex[1] + n++}, dutAttributes.get(i).getAttributeValue(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
        }
        for (int i = 0; i < testItems.size(); i++) {
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow, headIndex[1] + n++}, testItems.get(i).getTestedValue(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
        }

        currentRow++;
        return exCellList;
    }

    private List<ExCell> buildGrrDataTitle(Map<String, Object> testData, List<DUTAttribute> dutAttributes, List<TestItem> testItems, List<PSAttributeDto> psAttributeDtoList) {
        List<ExCell> exCellList = Lists.newArrayList();
        int n = 0;
        for (String key : testData.keySet()) {
            for (int i = 0; i < psAttributeDtoList.size(); i++) {
                if (key.equals(psAttributeDtoList.get(i).getName())) {
                    exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow, headIndex[1] + n}, psAttributeDtoList.get(i).getValue(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_title.toString())));
                    break;
                }
            }
            if (n == 0) {
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow + 1, headIndex[1] + n}, "Upper Limited", ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow + 2, headIndex[1] + n}, "Lower Limited", ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow + 3, headIndex[1] + n}, "Measurement Units", ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
            } else {
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow + 1, headIndex[1] + n}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow + 2, headIndex[1] + n}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow + 3, headIndex[1] + n}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
            }
            n++;
        }

        for (int i = 0; i < dutAttributes.size(); i++) {
            for (int j = 0; j < psAttributeDtoList.size(); j++) {
                if ((dutAttributes.get(i).getAttributeName()).equals(psAttributeDtoList.get(j).getName())) {
                    exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow, headIndex[1] + n}, psAttributeDtoList.get(j).getValue(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_title.toString())));
                    break;
                }
            }
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow + 1, headIndex[1] + n}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow + 2, headIndex[1] + n}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow + 3, headIndex[1] + n}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
            n++;
        }

        for (int i = 0; i < testItems.size(); i++) {
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow, headIndex[1] + n}, testItems.get(i).getName(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_title.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow + 1, headIndex[1] + n}, testItems.get(i).getUpperLimit(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow + 2, headIndex[1] + n}, testItems.get(i).getLowerLimit(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + currentRow + 3, headIndex[1] + n}, testItems.get(i).getUnitName(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.items_content.toString())));
            n++;
        }
        currentRow += 4;
        return exCellList;
    }

    private String formatDouble(Double str, int dig) {
        return String.format("%." + dig + "f", str);
    }

    @Override
    public XSSFWorkbook getCurrentWorkbook() {
        return workbook;
    }

    @Override
    public List<ExSheet> getSheets() {
        return sheets;
    }
}
